package com.ushio.gougouwangguo.controller;

import com.ushio.commonmodule.pojo.result.Result;
import com.ushio.gougouwangguo.entity.qo.ActionConfigMaterialsUpDateQo;
import com.ushio.gougouwangguo.entity.vo.ActionConfigMaterialsVo;
import com.ushio.gougouwangguo.service.IActionConfigMaterialsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author 张文凯
 * @since 2025-09-22
 */
@RestController
@RequestMapping("/actionConfigMaterials")
public class ActionConfigMaterialsController {

    @Autowired
    IActionConfigMaterialsService iActionConfigMaterialsService;

    @GetMapping("/get-actionConfig-materials")
    public Result<List<ActionConfigMaterialsVo>> getActionConfigMaterials(@RequestParam("actionConfigId") Integer actionConfigId){
        try{
           List<ActionConfigMaterialsVo> actionConfigMaterialsVoList = iActionConfigMaterialsService.getActionConfigMaterials(actionConfigId);
           return Result.success(actionConfigMaterialsVoList);
        }catch (Exception e){
            e.printStackTrace();
            return Result.fail(e.getMessage());
        }
    }

    @PostMapping("/update-actionConfig-materials")
    public Result updateActionConfigMaterials(@RequestBody ActionConfigMaterialsUpDateQo actionConfigMaterialsUpDateQo){
        try{

            iActionConfigMaterialsService.updateActionConfigMaterials(actionConfigMaterialsUpDateQo);

            return Result.success();

        }catch (Exception e){

            e.printStackTrace();

            return Result.fail(e.getMessage());

        }
    }

    @PostMapping("/delete")
    public Result deleteActionConfigMaterials(@RequestBody ActionConfigMaterialsUpDateQo actionConfigMaterialsUpDateQo){
        try{

            iActionConfigMaterialsService.deleteActionConfigMaterials(actionConfigMaterialsUpDateQo);

            return Result.success();

        }catch (Exception e){

            e.printStackTrace();

            return Result.fail(e.getMessage());

        }
    }


}
